//完美运动框架
window.onload = function() {
	var div1 = document.getElementById("div");
	var aList=document.getElementsByTagName("a");
	for(i=0;i<aList.length;i++){
		aList[i].onmouseover=function(){
			var iList=this.getElementsByTagName("i")[0];
			move(iList,{top:-8,opacity:0},function(){
				iList.style.top=20+"px";
			move(iList,{top:10,opacity:100});
			});
		}
	}
}

function move(obj, json, fun) {

	clearInterval(obj.timer);
	obj.timer = setInterval(function() {
		// div.style.width=div.offsetWidth-1+"px";//带边框
		//div.style.width还可以写成div.style["width"]
		//目前该属性的值
		// var iCurr = parseInt(obj.style[attribute]);
		for (var attribute in json) {
			var iCurr = 0;
			if (attribute == "opacity") {
				iCurr = Math.round(getStyle(obj, attribute) * 100); //透明度，curr获取
			} else {
				iCurr = parseInt(getStyle(obj, attribute));
			}
			if (iCurr == json[attribute]) {
				clearInterval(obj.timer);
				//判断有没有回调函数
				if (fun) {
					fun();
				}
			} else {
				//算速度
				var speed = (json[attribute] - iCurr) / 7;
				speed = speed > 0 ? Math.ceil(speed) : Math.floor(speed);
				// console.log(speed +"speed"); //-9

				if (attribute == "opacity") {
					obj.style.filter = "alpha(opacity:" + (iCurr + speed) + ")";
					obj.style.opacity = (iCurr + speed) / 100; //(100-9)/100=0.91
					// console.log(obj.style.opacity);
				} else {
					obj.style[attribute] = iCurr + speed + "px";
				}
			}
		}
	}, 20)

}

//获取对象的属性
function getStyle(obj, attribute) { //两个参数，对象和属性
	if (obj.currentStyle)
		return obj.currentStyle[attribute];
	else
		return getComputedStyle(obj, null)[attribute];
}